<template>
    <div style="width: 100%;margin: 10px auto;">
        <div class="operation" >
        <el-row type="flex" class="row-bg" justify="start">
            <el-input placeholder="请输入患者名"
                      prefix-icon="el-icon-search" clearable @clear="initData"
                      style="width: 200px;margin-right: 10px" v-model="keyword"
                      @keydown.enter.native="search"></el-input>
            <el-button icon="el-icon-search" type="primary" @click="search">
                搜索
            </el-button>
        </el-row>
        </div>
    <el-table
            :header-cell-style="{background:'#c3e0cd',color:'#606266'}"
            :fit="true"
            :data="patientList"
            border
            style="margin: 15px">
        <el-table-column
                type="selection"
                >
        </el-table-column>
        <el-table-column
                fixed
                prop="id"
                label="病人清单id"
                min-width="100">
        </el-table-column>
        <el-table-column
                prop="patientId"
                label="病人id"
                v-if="false"
                >
        </el-table-column>
        <el-table-column
                prop="patientName"
                label="病人姓名"
                min-width="100">
        </el-table-column>
        <el-table-column
                prop="inTime"
                label="入院时间"
                min-width="180">
        </el-table-column>
        <el-table-column
                prop="outTime"
                label="出院时间"
                min-width="180">
        </el-table-column>
    </el-table>
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20, 40]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
    </div>
</template>

<script>
    import MY from "../../global_variable";

    export default {
        name: "PatientList",
        data() {
            return {
                keyword:'',
                patientList:[],
                total:0,
                currentPage:1,
                pageSize:5,
                patientLists:[]
            }
        },
        mounted() {
            this.initData()
        },
        methods:{
            handleSizeChange: function (size) {
                this.pageSize = size;
                console.log(this.pageSize)  //每页下拉显示数据
                if(this.keyword!=''){
                    this.search()
                }else{
                    this.pageRequest(1,this.pageSize)
                }
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                if(this.keyword!=''){
                    this.search()
                }else{
                    this.pageRequest(currentPage,this.pageSize)
                }

            },
            pageRequest(start,size){
                var pn={
                    pageNum:start,
                    pageSize:size
                }
                this.getRequest(MY.myURL+'/patientList/getPatientListByPage',pn).then(resp=>{
                    if(resp){
                        this.patientList=resp.data.data.listPros
                        this.total=resp.data.data.total
                        this.currentPage=pn.pageNum
                    }
                })
            },
            search(){
                var pn={
                    patientName:this.keyword
                }
                this.getRequest(MY.myURL+'/patientList/fuzzyQueryPatientListProByPatientName',pn).then(resp=>{
                    console.log(resp)
                    if(resp.data.code=='4010'){
                        this.patientLists=resp.data.data
                        this.total=this.patientLists.length
                        let begin=0
                        let end=0
                        if(Math.ceil(this.total/this.pageSize)<this.currentPage){
                            begin=0
                            end=this.pageSize
                            this.currentPage=1
                        }else{
                            begin=(this.currentPage-1)*this.pageSize
                            end=(this.currentPage*this.pageSize)
                        }
                        this.patientList=this.patientLists.slice(begin,end)
                    }
                })
            },
            addDepAction(){

            },
            deleteClick(row) {
                console.log(row)
            },
            editData(row){
                console.log(row)
            },
            initData(){
                this.pageRequest(1,5)
            }
        }
    }
</script>

<style scoped>

</style>
